<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>找回密码 - 语义网络</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
            background: linear-gradient(135deg, #e6f0ff 0%, #f8e8e8 50%, #fff3e0 100%);
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #2c3e50;
        }

        .forgot-container {
            background: rgba(255, 255, 255, 0.95);
            padding: 2.5rem;
            border-radius: 15px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
            width: 100%;
            max-width: 450px;
            backdrop-filter: blur(10px);
        }

        .forgot-header {
            text-align: center;
            margin-bottom: 2.5rem;
        }

        .forgot-header h1 {
            color: #1a2a6c;
            font-size: 2.2rem;
            margin-bottom: 0.8rem;
            font-weight: 600;
        }

        .forgot-header p {
            color: #7f8c8d;
            font-size: 1rem;
            line-height: 1.5;
        }

        .form-group {
            margin-bottom: 1.8rem;
            position: relative;
        }

        .form-group label {
            display: block;
            margin-bottom: 0.6rem;
            color: #2c3e50;
            font-weight: 500;
            font-size: 1.1rem;
        }

        .form-group input {
            width: 100%;
            padding: 1rem;
            border: 2px solid #e0e0e0;
            border-radius: 8px;
            font-size: 1rem;
            transition: all 0.3s ease;
            background: rgba(255, 255, 255, 0.9);
        }

        .form-group input:focus {
            outline: none;
            border-color: #1a2a6c;
            box-shadow: 0 0 0 3px rgba(26, 42, 108, 0.1);
        }

        .reset-btn {
            width: 100%;
            padding: 1.2rem;
            background: linear-gradient(135deg, #1a2a6c 0%, #b21f1f 100%);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 1.1rem;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 1rem;
        }

        .reset-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
        }

        .links-container {
            display: flex;
            justify-content: center;
            margin-top: 1.5rem;
        }

        .link {
            color: #1a2a6c;
            text-decoration: none;
            font-size: 0.9rem;
            transition: color 0.3s ease;
        }

        .link:hover {
            color: #b21f1f;
            text-decoration: underline;
        }

        .footer {
            text-align: center;
            margin-top: 2rem;
            color: #7f8c8d;
            font-size: 0.9rem;
            padding-top: 1rem;
            border-top: 1px solid #eee;
        }

        .semantic-icon {
            font-size: 2.5rem;
            margin-bottom: 1rem;
            color: #1a2a6c;
        }

        .input-icon {
            position: absolute;
            right: 1rem;
            top: 2.8rem;
            color: #7f8c8d;
        }

        .instructions {
            font-size: 0.9rem;
            color: #7f8c8d;
            margin-bottom: 1.5rem;
            line-height: 1.5;
        }

        @media (max-width: 480px) {
            .forgot-container {
                margin: 1rem;
                padding: 2rem;
            }
        }
    </style>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
</head>
<body>
    <div class="forgot-container">
        <div class="forgot-header">
            <i class="fas fa-key semantic-icon"></i>
            <h1>找回密码</h1>
            <p>重置您的账户密码</p>
        </div>
        <div class="instructions">
            请输入您注册时使用的电子邮箱地址，我们将向该邮箱发送密码重置链接。
        </div>
        <form id="forgotPasswordForm">
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" id="username" name="username" required placeholder="请输入用户名">
                <i class="fas fa-user input-icon"></i>
            </div>
            <div class="form-group">
                <label for="oldPassword">旧密码</label>
                <input type="password" id="oldPassword" name="oldPassword" required placeholder="请输入旧密码">
                <i class="fas fa-lock input-icon"></i>
            </div>
            <div class="form-group">
                <label for="newPassword">新密码</label>
                <input type="password" id="newPassword" name="newPassword" required placeholder="请输入新密码">
                <i class="fas fa-lock input-icon"></i>
                <div class="password-requirements">
                    密码至少包含8个字符，包括字母和数字
                </div>
            </div>
            <button type="submit" class="reset-btn">重置密码</button>
            <div class="links-container">
                <a href="/user/login" class="link">返回登录</a>
            </div>
        </form>
        <div class="footer">
            <p>© 2024 语义网络平台 - 连接数据，创造价值</p>
        </div>
    </div>

    <script>
    document.getElementById('forgotPasswordForm').addEventListener('submit', function(e) {
        e.preventDefault();
        
        const username = document.getElementById('username').value;
        const oldPassword = document.getElementById('oldPassword').value;
        const newPassword = document.getElementById('newPassword').value;
        
        // 获取用户ID
        const user = JSON.parse(localStorage.getItem('user'));
        if (!user || !user.id) {
            alert('请先登录');
            window.location.href = '/user/login';
            return;
        }
        
        fetch('/api/auth/password', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            body: `userId=${user.id}&oldPassword=${encodeURIComponent(oldPassword)}&newPassword=${encodeURIComponent(newPassword)}`
        })
        .then(response => response.json())
        .then(data => {
            if (data.code === 200) {
                alert('密码修改成功，请重新登录');
                localStorage.removeItem('token');
                localStorage.removeItem('user');
                window.location.href = '/user/login';
            } else {
                alert(data.message);
            }
        })
        .catch(error => {
            console.error('Error:', error);
            alert('密码修改失败，请稍后重试');
        });
    });
    </script>
</body>
</html> 